﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace ASPNETVN.PORTAL.Components.Share
{
    public enum AttachmentStorageType
    {
        LINK,
        DATABASE,
        FILE

    }
    public partial class Attachment
    {
        // Select by foreign key return collection		
        public static IList<Attachment> SelectCollectionBy_ModuleID_ItemID(Guid moduleID, int itemID)
        {
            IList<Attachment> collection = new List<Attachment>();
            IDataReader reader = SelectReaderDynamic(string.Format("ModuleID = '{0}' AND ItemID = {1}", moduleID, itemID), "");
            while (reader.Read())
            {
                Attachment entity = new Attachment();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ItemID"))) entity.ItemID = reader.GetInt32(reader.GetOrdinal("ItemID"));
                if (!reader.IsDBNull(reader.GetOrdinal("FileName"))) entity.FileName = reader.GetString(reader.GetOrdinal("FileName"));
                if (!reader.IsDBNull(reader.GetOrdinal("FileUrl"))) entity.FileUrl = reader.GetString(reader.GetOrdinal("FileUrl"));
                if (!reader.IsDBNull(reader.GetOrdinal("FileSize"))) entity.FileSize = reader.GetInt64(reader.GetOrdinal("FileSize"));
                if (!reader.IsDBNull(reader.GetOrdinal("ContentType"))) entity.ContentType = reader.GetString(reader.GetOrdinal("ContentType"));
                if (!reader.IsDBNull(reader.GetOrdinal("StorageType"))) entity.StorageType = reader.GetString(reader.GetOrdinal("StorageType"));
                if (!reader.IsDBNull(reader.GetOrdinal("BinaryContent"))) entity.BinaryContent = (byte[])reader["BinaryContent"];
                collection.Add(entity);
            }
            reader.Close();
            return collection;
        }
        //---------------------------------------------------------------------------------------------
    }
}
